<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  div {
    width: 300px;
    height: 25px;
    text-align: center;
    border: 1px solid black;
  }
</style>

<body>
  <div></div>
  <script>
    // const date = new Date()
    // document.write(`${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}`)
    const div = document.querySelector('div')
    function getMyDate() {
      const date = new Date()
      let h = date.getHours() > 10 ? date.getHours() : '0' + date.getHours()
      let m = date.getMinutes() > 10 ? date.getMinutes() : '0' + date.getMinutes()
      let s = date.getSeconds() > 10 ? date.getSeconds() : '0' + date.getSeconds()
      return `今天是${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日
      ${h}点${m}分${s}秒`

    }
    div.innerHTML = getMyDate()
    setInterval(function () {
      div.innerHTML = getMyDate()
    }, 1000)
  </script>
</body>

</html>